﻿package mortal.game.scene3D.player.entity
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import baseEngine.basic.*;
    import baseEngine.modifiers.*;
    import frEngine.effectEditTool.temple.*;
    import frEngine.pools.*;
    import frEngine.shader.filters.*;
    import frEngine.shader.filters.fragmentFilters.extra.*;
    import frEngine.shader.filters.vertexFilters.*;
    import mortal.component.gconst.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.player.weapon.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.scene3D.player.type.*;

    public class UserModelPlayer extends Game2DPlayer
    {
        private var _bodyPlayer:ActionPlayer;
        private var _weaponPlayer:WeaponPlayer;
        private var _weaponHangEffect:EffectPlayer;
        private var _hairPlayer:ActionPlayer;
        private var _wingPlayer:ActionPlayer;
        private var _wingHangEffect:EffectPlayer;
        private var _clothHangEffect:EffectPlayer;
        protected var _isShowWeaponEffect:Boolean;
        protected var _isShowClothesEffect:Boolean;
        protected var _isShowWingEffect:Boolean;
        protected var _career:int;
        protected var _sex:int;
        protected var _weapon:int;
        protected var _clothes:int;
        protected var _hair:int;
        protected var _wing:int;
        protected var _isHideWing:Boolean;
        protected var _vip:int;
        protected var _renderList:RenderList;
        private var _useLight:Boolean = false;

        public function UserModelPlayer()
        {
            return;
        }// end function

        public function get bodyPlayer() : ActionPlayer
        {
            return this._bodyPlayer;
        }// end function

        protected function initPlayer() : void
        {
            if (!this._bodyPlayer)
            {
                this._bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
                this._bodyPlayer.enabledPool = false;
            }
            this._bodyPlayer.changeAction(ActionName.Stand);
            this._bodyPlayer.hangBoneName = BoneConst.MountHangModelBone;
            this._bodyPlayer.selectEnabled = false;
            this._bodyPlayer.timerContorler = this.timerContorler;
            this._bodyPlayer.play();
            this.timerContorler.active();
            this.addChild(this._bodyPlayer);
            if (!this._weaponPlayer)
            {
                this._weaponPlayer = FrObjectPool.getObject(WeaponPlayer, this);
                this._weaponPlayer.enabledPool = false;
            }
            this._weaponPlayer.hangBoneName = BoneConst.ModelHangWeaponBone;
            if (!this._hairPlayer)
            {
                this._hairPlayer = FrObjectPool.getObject(ActionPlayer, this);
                this._hairPlayer.enabledPool = false;
            }
            this._hairPlayer.changeAction(ActionName.Stand);
            this._hairPlayer.hangBoneName = BoneConst.ModelHangHairBone;
            this._hairPlayer.selectEnabled = false;
            this._hairPlayer.enabeldDrawDefault = false;
            this._hairPlayer.timerContorler = this.timerContorler;
            this._hairPlayer.play();
            return;
        }// end function

        protected function initWingPlayer() : void
        {
            if (!this._wingPlayer)
            {
                this._wingPlayer = FrObjectPool.getObject(ActionPlayer, this);
                this._wingPlayer.enabledPool = false;
            }
            this._wingPlayer.changeAction(ActionName.Stand);
            this._wingPlayer.hangBoneName = BoneConst.ModelHangWingBone;
            this._wingPlayer.selectEnabled = false;
            this._wingPlayer.enabeldDrawDefault = false;
            this._wingPlayer.timerContorler = this.timerContorler;
            this._wingPlayer.play();
            return;
        }// end function

        public function updateIsShowEffect(param1:Boolean, param2:Boolean, param3:Boolean) : void
        {
            this._isShowWeaponEffect = param1;
            this._isShowClothesEffect = param2;
            this._isShowWingEffect = param3;
            return;
        }// end function

        public function updateInfo(param1:int, param2:int, param3:int, param4:int, param5:int = 0, param6:int = 0, param7:int = 0, param8:Boolean = false) : void
        {
            this.sex = param2;
            this.career = param1;
            this.clothes = param3;
            this.weapon = param4;
            this.hair = param5;
            this.wing = param6;
            this.vip = param7;
            this.isHideWing = param8;
            this.initPlayer();
            this.loadClothes();
            this.loadWeapon();
            this.loadHair();
            this.loadWing();
            return;
        }// end function

        public function set sex(param1:int) : void
        {
            this._sex = param1;
            return;
        }// end function

        public function set career(param1:int) : void
        {
            this._career = param1;
            return;
        }// end function

        public function set weapon(param1:int) : void
        {
            this._weapon = param1;
            return;
        }// end function

        public function set clothes(param1:int) : void
        {
            this._clothes = param1;
            return;
        }// end function

        public function loadWeapon() : void
        {
            var _loc_1:TPlayerModel = null;
            var _loc_2:int = 0;
            _loc_1 = this.getModelInfo(ModelType.WEAPONS, this._weapon);
            if (_loc_1)
            {
                this._weaponPlayer.load(_loc_1.mesh + ".md5mesh", _loc_1.texture, this._renderList);
                this._bodyPlayer.hang(this._weaponPlayer);
                if (this._weaponHangEffect)
                {
                    this._weaponHangEffect.dispose();
                    this._weaponHangEffect = null;
                }
                if (_loc_1.selfEffect && (this._isShowWeaponEffect || VipConfig.instance.isShowEffect(EVipRecordType._EVipRecordTypeWeaponEffect, this.vip)))
                {
                    this._weaponHangEffect = EffectPlayerPool.instance.getEffectPlayer(_loc_1.selfEffect, this._weaponPlayer, this._renderList, true);
                    if (this._weaponHangEffect.temple is TempleRole)
                    {
                        (this._weaponHangEffect.temple as TempleRole).setRoleParams(this._weaponPlayer, null, null);
                    }
                    this._weaponHangEffect.play(PlayMode.ANIMATION_LOOP_MODE);
                }
            }
            else
            {
                if (this._weaponHangEffect)
                {
                    this._weaponHangEffect.dispose();
                    this._weaponHangEffect = null;
                }
                this._bodyPlayer.unHang(this._weaponPlayer);
                this.removeChild(this._weaponPlayer);
            }
            return;
        }// end function

        public function loadHair() : void
        {
            var _loc_1:TPlayerModel = null;
            _loc_1 = this.getModelInfo(ModelType.HAIR, this._hair);
            if (_loc_1)
            {
                this._hairPlayer.load(_loc_1.mesh + ".md5mesh", _loc_1.bone + ".skeleton", _loc_1.texture, this._renderList);
                this._bodyPlayer.hang(this._hairPlayer);
            }
            else
            {
                this._bodyPlayer.unHang(this._hairPlayer);
                this.removeChild(this._hairPlayer);
            }
            return;
        }// end function

        public function loadWing() : void
        {
            var _loc_1:TPlayerModel = null;
            _loc_1 = this.getModelInfo(ModelType.WING, this._wing);
            if (_loc_1 && !this._isHideWing)
            {
                this.initWingPlayer();
                this._wingPlayer.load(_loc_1.mesh + ".md5mesh", _loc_1.bone + ".skeleton", _loc_1.texture, this._renderList);
                this._bodyPlayer.hang(this._wingPlayer);
                if (this._wingHangEffect)
                {
                    this._wingHangEffect.dispose();
                    this._wingHangEffect = null;
                }
                if (_loc_1.selfEffect && (this._isShowWingEffect || VipConfig.instance.isShowEffect(EVipRecordType._EVipRecordTypeWingEffect, this.vip)))
                {
                    this._wingHangEffect = EffectPlayerPool.instance.getEffectPlayer(_loc_1.selfEffect, this._wingPlayer, this._renderList, true);
                    if (this._wingHangEffect.temple is TempleRole)
                    {
                        (this._wingHangEffect.temple as TempleRole).setRoleParams(this._wingPlayer, null, null);
                    }
                    this._wingHangEffect.play(PlayMode.ANIMATION_LOOP_MODE);
                }
            }
            else
            {
                if (this._wingHangEffect)
                {
                    this._wingHangEffect.dispose();
                    this._wingHangEffect = null;
                }
                if (this._wingPlayer && this._bodyPlayer)
                {
                    this._bodyPlayer.unHang(this._wingPlayer);
                    this.removeChild(this._wingPlayer);
                }
            }
            return;
        }// end function

        public function loadClothes() : void
        {
            var _loc_1:TPlayerModel = null;
            _loc_1 = this.getModelInfo(ModelType.CLOTHES, this._clothes);
            if (_loc_1)
            {
                this._bodyPlayer.load(_loc_1.mesh + ".md5mesh", _loc_1.bone + ".skeleton", _loc_1.texture, this._renderList);
                if (this._clothHangEffect)
                {
                    this._clothHangEffect.dispose();
                    this._clothHangEffect = null;
                }
                if (_loc_1.selfEffect && (this._isShowClothesEffect || VipConfig.instance.isShowEffect(EVipRecordType._EVipRecordTypeClothesEffect, this.vip)))
                {
                    this._clothHangEffect = EffectPlayerPool.instance.getEffectPlayer(_loc_1.selfEffect, this._bodyPlayer, this._renderList, true);
                    if (this._clothHangEffect.temple is TempleRole)
                    {
                        (this._clothHangEffect.temple as TempleRole).setRoleParams(this._bodyPlayer, null, null);
                    }
                    this._clothHangEffect.play(PlayMode.ANIMATION_LOOP_MODE);
                }
            }
            else if (this._clothHangEffect)
            {
                this._clothHangEffect.dispose();
                this._clothHangEffect = null;
            }
            return;
        }// end function

        public function getModelInfo(param1:int, param2:int) : TPlayerModel
        {
            return PlayerModelConfig.instance.getModelInfo(param1, param2, this._sex, this._career);
        }// end function

        public function setRenderList(param1:RenderList) : void
        {
            this._renderList = param1;
            if (this._weaponHangEffect)
            {
                this._weaponHangEffect.renderList = param1;
            }
            if (this._wingHangEffect)
            {
                this._wingHangEffect.renderList = param1;
            }
            if (this._clothHangEffect)
            {
                this._clothHangEffect.renderList = param1;
            }
            if (this._bodyPlayer)
            {
                this._bodyPlayer.renderList = param1;
            }
            if (this._weaponPlayer)
            {
                this._weaponPlayer.renderList = param1;
            }
            if (this._hairPlayer)
            {
                this._hairPlayer.renderList = param1;
            }
            if (this._wingPlayer)
            {
                this._wingPlayer.renderList = param1;
            }
            return;
        }// end function

        public function set scaleAll(param1:Number) : void
        {
            this._bodyPlayer.scaleX = param1;
            this._bodyPlayer.scaleY = param1;
            this._bodyPlayer.scaleZ = param1;
            return;
        }// end function

        override public function hoverTest(param1:Number, param2:Number, param3:Number, param4:Number) : Boolean
        {
            return false;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            this._career = 0;
            this._sex = 0;
            this._weapon = 0;
            this._clothes = 0;
            this._renderList = null;
            this._isShowWeaponEffect = false;
            this._isShowClothesEffect = false;
            this._isShowWingEffect = false;
            if (this._weaponHangEffect)
            {
                this._weaponHangEffect.dispose(param1);
                this._weaponHangEffect = null;
            }
            if (this._wingHangEffect)
            {
                this._wingHangEffect.dispose(param1);
                this._wingHangEffect = null;
            }
            if (this._clothHangEffect)
            {
                this._clothHangEffect.dispose(param1);
                this._clothHangEffect = null;
            }
            if (this._weaponPlayer)
            {
                if (this._bodyPlayer)
                {
                    this._bodyPlayer.unHang(this._weaponPlayer);
                }
                this._weaponPlayer.dispose(param1);
                this._weaponPlayer = null;
            }
            if (this._hairPlayer)
            {
                if (this._bodyPlayer)
                {
                    this._bodyPlayer.unHang(this._hairPlayer);
                }
                this._hairPlayer.dispose(param1);
                this._hairPlayer = null;
            }
            if (this._wingPlayer)
            {
                if (this._bodyPlayer)
                {
                    this._bodyPlayer.unHang(this._wingPlayer);
                }
                this._wingPlayer.dispose(param1);
                this._wingPlayer = null;
            }
            if (this._bodyPlayer)
            {
                this._bodyPlayer.dispose(param1);
                this._bodyPlayer = null;
            }
            super.dispose(param1);
            return;
        }// end function

        public function useLight() : void
        {
            this._useLight = true;
            var _loc_1:* = this._bodyPlayer;
            if (!_loc_1.material.materialParams.hasFilter(FilterType.VertexNormalFilter))
            {
                _loc_1.material.materialParams.addFilte(new VertexNormalFilter());
            }
            if (!_loc_1.material.materialParams.hasFilter(FilterType.PlayerBackLightFilter))
            {
                _loc_1.material.materialParams.addFilte(new PlayerBackLightFilter());
            }
            return;
        }// end function

        public function get hair() : int
        {
            return this._hair;
        }// end function

        public function set hair(param1:int) : void
        {
            this._hair = param1;
            return;
        }// end function

        public function get wing() : int
        {
            return this._wing;
        }// end function

        public function set wing(param1:int) : void
        {
            this._wing = param1;
            return;
        }// end function

        public function get vip() : int
        {
            return this._vip;
        }// end function

        public function set vip(param1:int) : void
        {
            this._vip = param1;
            return;
        }// end function

        public function get clothes() : int
        {
            return this._clothes;
        }// end function

        public function get weapon() : int
        {
            return this._weapon;
        }// end function

        public function get isHideWing() : Boolean
        {
            return this._isHideWing;
        }// end function

        public function set isHideWing(param1:Boolean) : void
        {
            this._isHideWing = param1;
            return;
        }// end function

    }
}
